<template>
	<view class="content">
		<view class="record-view" v-for="(item, index) in records" :key="index" @click="toDetail(item)">
			<view class="left-view">
				<view class="title">{{item.subject}}</view>
				<view class="time">{{item.time}}</view>
			</view>
			<view class="right-view" :style="{'background-color': item.type == '1' ? '#18BC37' : 'red'}">{{item.type == '1' ? '答对' : '答错'}}</view>
		</view>
		<view class="cue-words" v-if="records.length == 0">您还未答过题哦</view>
		
		<!-- 答题详情弹窗 -->
		<view class="pop" v-show="isDisplay" >
			<view class="pop-title">
				{{ detail.subject }}
			</view>
			<view class="pop-btn">
				<button  v-for="(item, index) in detail.options" :key="index"  type="default"
				:style="{'background-color': index === trueIndex ? '#18BC37':'',
						'color': index===trueIndex ? '#FFFFFF': '#212121'
			}"
			>{{ item.option }}</button>
			</view>
			
			<view class="sure" @click="sure">
				<view>
					返回
				</view>
			</view>
	    </view>


	</view>
</template>

<script>
	import http from '@/api/backend.js'
	export default {
		data() {
			return {
				userId: '',
				records: [],
				detail: {},
				isDisplay: false,
				trueIndex:0,
				pageNum:1,
				pageSize:10
			};
		},
		onLoad(option) {
			this.userId = option.userId
			this.queryAnswerRecords(this.userId, 1, 10)
		},
		onPullDownRefresh() {
			this.records=[]
			this.queryAnswerRecords(this.userId, 1, 10)
			uni.stopPullDownRefresh()
		},
		onReacnBottom(){
			this.pageNum+=1
			this.queryAnswerRecords(this.userId, this.pageNum, 10)
		},
		methods: {
			// 查询答题记录
			queryAnswerRecords(userId, pageNum, pageSize) {
				http.queryAnswerRecords({userId: this.userId, pageNum: pageNum, pageSize: pageSize}).then(res => {
					for(let i =0;i<res.data.length;i++){
						this.records.push(res.data[i])
					}
				})
			},
			sure() {
				this.isDisplay = false
			},

			toDetail(item) {
				http.getAnswer({answerId: item.answerId}).then(res => {
					this.detail = res.data
					for(let i=0;i<this.detail.options.length;i++){
						if(this.detail.options[i]===this.detail.answer) this.trueIndex = i
					}
					console.log(this.trueIndex);
					this.isDisplay = true

				})
			}
		}
	}
</script>

<style lang="scss">
	.content {
		padding: 20rpx;
		
	}
	.record-view {
		display: flex;
		align-items: center;
		padding-bottom: 20rpx;
		border-bottom: 2rpx solid #ececec;
		margin-top: 30rpx;
		display: flex;
		justify-content: space-between;
		.left-view {
			float: left;
			
			.title {
				font-size: 30rpx;
				color: #212121;
				width: 86%;
				// 文字超出...
				text-overflow: -o-ellipsis-lastline;
				overflow: hidden;
				text-overflow: ellipsis;
				display: -webkit-box;
				-webkit-line-clamp: 1;
				line-clamp: 1;
				-webkit-box-orient: vertical;
			}
			
			.time {
				margin-top: 16rpx;
				font-size: 28rpx;
				color: #acacac;
			}
		}
		.right-view {
			float: right;
			font-size: 26rpx;
			width: 12%;
			padding: 10rpx;
			padding-left: 20rpx;
			padding-right: 20rpx;
			text-align: center;
			color: #FFFFFF;
			border-radius: 50rpx;
		}
	}
	
	.cue-words {
		text-align: center;
		font-size: 28rpx;
		color: #778288;
		margin-top: 12rpx;
	}
	//详情弹窗
	.pop {
    position: absolute;
	border:1rpx solid #d1d1d1;
	display: flex;
	flex-direction: column ;
	justify-content: space-between;
    left: 50%;
    top: 50%;
    transform: translate(-50%,-50%);
    background-color: #fff;
    border-radius: 16rpx;
    height: 576rpx;
    z-index: 99;
    width: 640rpx;
    padding: 30rpx 0;
	
  	}
	.pop .pop-title {
		text-align: center;
		font-size: 34rpx;
		font-weight: 500;
		margin-bottom: 38rpx;
		border-bottom: 1rpx solid #d1d1d1;
	}
	.pop-btn button{
		color: #FFFFFF;
	}
	.sure {
		width: 100%;
		border-top: 1rpx solid #d1d1d1;
		height: 60rpx;
		text-align: center;
		line-height: 60rpx;
		color: #02A53C;
		font-size: 34rpx;
		font-weight: 500;
			
	}

</style>
